<template>
  <j-modal
    :title="title"
    :width="600"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :rules="validatorRules" :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-form-model-item label="手机号码">
          <a-input v-model="form.phone" disabled />
        </a-form-model-item>
        <a-form-model-item label="姓名/代号">
          <a-input v-model="form.name" />
        </a-form-model-item>
        <a-form-model-item label="归属地">
          <a-input v-model="form.phoneArea" disabled />
        </a-form-model-item>
        <a-form-model-item label="案事件编号">
          <a-input v-model="form.incidentCode" disabled />
        </a-form-model-item>
        <a-form-model-item label="案事件名称">
          <a-input v-model="form.incidentName" disabled />
        </a-form-model-item>
        <a-form-model-item label="任务编号">
          <a-input v-model="form.taskCode" disabled />
        </a-form-model-item>
        <a-form-model-item label="标签" v-if="type==='keyPersonnel'" prop="labelId">
          <j-category-select v-model="form.labelId" pcode="B03" :multiple="true"/>
        </a-form-model-item>
        <a-form-model-item label="标签" v-if="type==='samplesPersonnel'" prop="labelName">
          <j-dict-select-tag v-model="form.labelName" placeholder="请选择" dictCode="sample_person_label" />
        </a-form-model-item>
        <a-form-model-item label="指数">
          <a-input-number v-model="form.indexNum" placeholder="请输入指数" :min="0" :max="10" style="width:40%;" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
    <template slot="footer">
      <a-button key="back" @click="handleCancel">取消</a-button>
      <a-button key="submit" type="primary" @click="handleOk">确定</a-button>
    </template>
  </j-modal>
</template>

<script>
import * as peopleApi from '@/api/wxSmuggle/people.js'
export default {
  name: 'editModal',
  props: {
    title: {
      type: String,
      default: ''
    },
    // keyPersonnel走私重点人，samplesPersonnel负样本人员库
    type: {
      type: String,
      default: 'keyPersonnel'
    }
  },
  data() {
    return {
      visible: false,
      disableSubmit: false,
      form: {},
      labelCol: { span: 6 },
      wrapperCol: { span: 16 },
      confirmLoading: false,
      selectedKeys: null,
      validatorRules: {
        labelId: [
          { required: true, message: '请选择标签', trigger: 'change' },
        ],
        labelName: [
          { required: true, message: '请选择标签', trigger: 'change' },
        ]
      }
    }
  },
  computed: {},
  methods: {
    add() {
      this.visible = true
      this.$nextTick(() => {})
    },
    edit(record) {
      this.visible = true
      this.form = Object.assign({}, record)
      this.$nextTick(() => {})
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      let api
      if(this.type==='keyPersonnel') {
        api = peopleApi.wxFocusPersonEdit(this.form)
      } else if(this.type==='samplesPersonnel') {
        api = peopleApi.wxSamplePersonEdit(this.form)
      }
      this.$refs.form.validate((valid)=> {
        if (valid) {
          api.then(res => {
            if (res.success) {
              this.$message.success(res.message)
              this.$emit('ok');
              this.handleCancel()
            } else {
              this.$message.warn(res.message)
            }
          })
          .catch(e => {
            this.$message.warn('请求失败！')
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>
<style lang="less" scoped></style>
